"ui";
//2019.4.10
ui.layout(
    <vertical bg="#d3d3d3">
        <horizontal>
            <img id="exit" src="file://./res/ic_keyboard_backspace_black_48dp.png" w="40" h="40" gravity="center"/>
            <text text="小数字"  textColor="#333333" textSize="27sp" typeface="serif" gravity="top|center" w="*" textStyle="bold"/>
        </horizontal>
        <vertical padding="10">
            <input textSize="28sp" id="input" singleLine="true" hint="点击下面的数字"/>
        </vertical>
        <vertical>
            <horizontal gravity="center">
                <button id="clos" text="清空" style="Widget.AppCompat.Button.Colored"/>
                <button id="copy" text="复制" style="Widget.AppCompat.Button.Colored"/>
            </horizontal>
        </vertical>
        <vertical w="*" padding="10">
            <text text="上层数字" gravity="center"/>
        </vertical>
        <grid id="icons" spanCount="5" h="auto" bg="?selectableItemBackgroundBorderless">
            <button h="50dp" size="25dp" layout_gravity="center_vertical" gravity="center" text="{{this}}" bg="?selectableItemBackgroundBorderless"/>
        </grid>
        <vertical w="*" padding="10">
            <text text="下层数字" gravity="center"/>
        </vertical>
        <grid id="icons2" spanCount="5" h="auto" bg="?selectableItemBackgroundBorderless">
            <button h="50dp" size="25dp" layout_gravity="center_vertical" gravity="center" text="{{this}}" bg="?selectableItemBackgroundBorderless"/>
        </grid>
        
    </vertical>
);
//ui.input.setEnabled(false);
ui.input.setFocusable(false);

ui.exit.on("click", () => {
    ui.finish()
});

var top = ["º", "¹", "²", "³", "⁴", "⁵", "⁶", "⁷", "⁸", "⁹"];
var boom = ["₀", "₁", "₂", "₃", "₄", "₅", "₆", "₇", "₈", "₉"];
var icons = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"]

//ui.post(() => {
    ui.icons.setDataSource(icons);
    ui.icons2.setDataSource(icons);
//});
ui.icons.on("item_click", function(icon) {
    ui.input.setText(ui.input.text() + top[icon]);
});
ui.icons2.on("item_click", function(icon) {
    ui.input.setText(ui.input.text() + boom[icon]);
});

ui.clos.on("click",()=>{
    ui.input.setText("");
});
ui.copy.on("click",()=>{
    let text= ui.input.text();
    if(text){
        setClip(text);
        toast("复制成功！");
    }
});
